const path = require('path');
const webpack=require('webpack')
var HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require("extract-text-webpack-plugin");

module.exports = {
    //入口
    entry: './src/app.jsx',
    //出口
    output: {
        path: path.resolve(__dirname, 'dist'),
        publicPath: "/shop-react/",
        filename: 'js/app.js'
    },
    resolve: {
      alias:{
          page:path.resolve(__dirname, 'src/page'),
          component:path.resolve(__dirname, 'src/component'),
          until:path.resolve(__dirname, 'src/until'),
          service:path.resolve(__dirname, 'src/service'),
      }
    },
    module: {
        //处理非js文件的规则
        //处理jsx
        rules: [
            {
                test: /\.jsx$/,
                exclude: /(node_modules)/,
                use: {
                    loader: 'babel-loader',
                    options: {
                        presets: ['env','react']
                    }
                }
            },
            //css文件处理
            {
                test: /\.css$/,
                use: ExtractTextPlugin.extract({
                    fallback: "style-loader",
                    use: "css-loader"
                })
            },
            //scss文件处理
            {
                test: /\.scss$/,
                use: [
                    "style-loader",
                    "css-loader",
                    "sass-loader"
                ]
            },
            //图片配置
            {
                test: /\.(png|jpg|gif)$/i,
                use: [
                    {
                        loader: 'url-loader',
                        options: {
                            limit: 8192,
                            name:'resource/[name].[ext]'
                        }
                    }
                     ]
            },
            //字体图标配置
            {
                test: /\.(eot|svg|woff|woff2|otf|ttf)$/i,
                use: [
                    {
                        loader: 'url-loader',
                        options: {
                            limit: 8192,
                            name:'resource/[name].[ext]'
                        }
                    }
                ]
            }
        ]
    },

    //插件
    plugins: [
        //处理html文件
        new HtmlWebpackPlugin({
        template: './src/index.html',
            favicon: 'shop.ico'
        }),
        //独立css件
        new ExtractTextPlugin("css/[name].css"),
        //提出公共模块
        new webpack.optimize.CommonsChunkPlugin({
            name:'common',
            filename:'js/base.js'
        })

    ],
    devServer: {
        // port:8086,
        historyApiFallback:{
            index:'/dist/index.html'
        },
        proxy:{
            'http://lin-react.gitee.io/manage':{
                target:'http://admintest.happymmall.com',
                changeOrigin:true
            },
            "http://lin-react.gitee.io/user/logout.do":{
                target:'http://admintest.happymmall.com',
                changeOrigin:true
            }
        }
  }
};